/**
 * Created by Amaris on 2016/12/5.
 */


var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * 路演信息
 * @type {void|*}
 *
 */
module.exports = Waterline.Collection.extend({
    identity: 'roadshow',
    tableName: 'tb_roadshow',
    connection: "mysql",
    attributes: {

        rowId: {
            type: 'string',
            unique: true,
            primaryKey: true,
            required: true,
            columnName: 'rowid',
            uuidv4: true,
            defaultsTo: function () {
                return uuid.v4();
            }
        },
        seller: {
            type: 'string',
            required: true,
            columnName: 'seller',
            model: 'seller'
        },
        industry: {
            type: 'string',
            required: true,
            columnName: 'industry',
            model: 'industry'
        },
        companyName: {
            type: 'string',
            columnName: 'companyname'
        },
        startTime: {
            type: 'datetime',
            required: true,
            before: function () {
                return this.finishTime;
            },
            columnName: 'starttime'
        },
        finishTime: {
            type: 'datetime',
            required: true,
            after: function () {
                return this.startTime;
            },
            columnName: 'finishtime'
        },
        type: {
            type: 'string',
            required: true,
            columnName: 'type'
        },
        recommend: {
            type: 'string',
            columnName: 'recommend'
        },
        content: {
            type: 'string',
            columnName: 'content'
        },
        createUid: {
            type: 'string',
            required: true,
            columnName: 'createuid',
            model: 'user'
        },
        score: {
            type: 'string',
            columnName: 'score'
        },
        scoreUid: {
            type: 'string',
            columnName: 'scoreuid',
            model: 'user'
        },
        scoreTime: {
            type: 'datetime',
            columnName: 'scoretime'
        },
        /**2017年03月20日 新增**/
        address: {
            type: 'string',
            columnName: 'address',
            model: 'dic_roadshowlocation'
        },
        guestCompany: {
            type: 'string',
            columnName: 'guestcompany'
        },
        guestPro: {
            type: 'string',
            columnName: 'guestpro'
        },
        fieldPro: {
            type: 'string',
            columnName: 'fieldpro'
        },
        subtypeCompany: {
            type: 'string',
            columnName: 'subtypecompany'
        },
        companyRecommend: {
            type: 'string',
            columnName: 'companyrecommend'
        },
        /**
         * 2017年04月14日新增
         */
        teamId: {
            type: 'string',
            columnName: 'teamid'
        },
        toJSON: function () {
            var obj = this.toObject();
            obj.scoreTime = moment(obj.scoreTime).format('YYYY/MM/DD hh:mm');
            obj.startTime = moment(obj.startTime).format('YYYY/MM/DD hh:mm');
            obj.finishTime = moment(obj.finishTime).format('YYYY/MM/DD hh:mm');
            obj.createdAt = moment(obj.createdAt).format('YYYY/MM/DD hh:mm');
            obj.updatedAt = moment(obj.updatedAt).format('YYYY/MM/DD hh:mm');

            return obj;
        }
    }
});
